const { show } = require("../../utils/MusicHttp");
const MusicHttp = require("../../utils/MusicHttp")
Page({

  data: {
    hot:[],
    cities:[],
    search:[],
    citys:[]
  },

  onLoad:async function (options) {
    var ct = wx.getStorageSync("citys");
    var citys = this.data.citys;
    citys.push(ct)
    var city = await MusicHttp.getCityHttp();
    console.log(city);
      var citys = city.data.data.cities;
      var hot = city.data.data.hotCities;
      var hots = []
      console.log(citys);
      console.log(hot);
      hot.forEach(item=>{
        var {name} = item;
        hots.push(name)
      })
      this.setData({
        cities:citys,
        hot:hots,
        citys:ct,
      })
   
  },
  // onSearch(e){
  //   var search = this.data.search;
  //   var value = e.detail;
  //   search.unshift(value);
  //   this.setData({
  //     search
  //   })
  // },
  onClick(e){
    var citys = this.data.citys
    var {aid} = e.currentTarget.dataset;
    console.log(aid);
    wx.setStorageSync('city', aid)
    if(!citys.includes(aid)){
      citys.unshift(aid);
    }else{
      var index = citys.indexOf(aid);
      citys.splice(index,1)
      citys.unshift(aid);
    }
    if(citys.length>2){
      citys = citys.slice(0,3)
    }
    
    wx.setStorageSync('citys', citys)
    wx.navigateBack()
    this.setData({
      citys
    })
  },
  async onChange(e){
    var value = e.detail;
   var res = await MusicHttp.show(value)
   console.log(res);
  //  wx.setStorageSync('city', res)
   this.setData({
     res,
   })
  }
  
})